import os
import pathlib

def count_typ_files(directory):
    count = 0
    for root, _, files in os.walk(directory):
        for file in files:
            if pathlib.Path(file).suffix == '.typ':
                count += 1
    return count

if __name__ == "__main__":
    target_dir = "typst-book"
    result = count_typ_files(target_dir)
    
    output_file = "typ_file_count.txt"
    with open(output_file, 'w') as f:
        f.write(f"Number of .typ files in {target_dir}: {result}")
    
    print(f"Result saved to {output_file}")